﻿// Copyright (c)  MOKEYISH. All rights reserved.
// Licensed under the MIT License, See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Text;

namespace NSQL.Sharpen
{
    internal static class StringBuilderExtensions
    {
#if NETSTANDARD1_6 || NETSTANDARD2_0
        public static StringBuilder AppendJoin(this StringBuilder builder, string separator, IEnumerable<string> values)
        {
            using (var enumerator = values.GetEnumerator())
            {
                if (!enumerator.MoveNext())
                {
                    return builder;
                }

                var current = enumerator.Current;
                builder.Append(current);
                while (enumerator.MoveNext())
                {
                    builder.Append(separator);
                    current = enumerator.Current;
                    if ((object) current != null)
                        builder.Append(current);
                }
            }
            return builder;
        }
        
        public static StringBuilder AppendJoin(this StringBuilder builder, string separator, IEnumerable<StringBuilder> values)
        {
            using (var enumerator = values.GetEnumerator())
            {
                if (!enumerator.MoveNext())
                {
                    return builder;
                }

                var current = enumerator.Current;
                if (current != null) builder.Append(current);
                while (enumerator.MoveNext())
                {
                    builder.Append(separator);
                    current = enumerator.Current;
                    if (current != null) builder.Append(current);
                }
            }
            return builder;
        }
        
#endif
    }
}